package org.weasel.controllers;

import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.weasel.business.Developer;
import org.weasel.views.DeveloperEditView;

public class DeveloperEditViewController {
	private static DeveloperEditViewController instance = null;
	private DeveloperViewController controller;
	private Developer developer;
	
	private DeveloperEditViewController(){
		
	}
	
	public static DeveloperEditViewController instance(){
		if(instance == null)
			instance = new DeveloperEditViewController();
		return instance;
	}

	public void setController(DeveloperViewController controller) {
		this.controller = controller;
	}
	
	public void setDeveloper(Developer developer) {
		this.developer = developer;
	}

	public void showDeveloperEditView(){
		try {
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(DeveloperEditView.ID);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		DeveloperEditView view = (DeveloperEditView) page.findView(DeveloperEditView.ID);
		view.showDeveloperInformation(developer);
	}

	public void setDeveloperName(String text) {
		developer.setName(text);
		controller.refreshViewer();
		ApplicationController.instance().changesOccured();
	}
	
	public void setDeveloperEmail(String text){
		developer.setEmail(text);
		ApplicationController.instance().changesOccured();
	}
	
	public void setDeveloperPosition(String text){
		developer.setPosition(text);
		ApplicationController.instance().changesOccured();
	}
	
}
